﻿@model yq.IBase.Table.TableInfo
           @{
    Layout = null;
}
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text;
using System.Data; 
using yq.IBase; 
using yq.Dictionary; 
using yq.Basis; 
using yq.Model.Logic;
using System.Collections; 
using Db; 
using System.Data.Common;

namespace yq.Model.Base 
{
    ///<summary>
    /// @(Model.Name) - 对象基础类
    /// </summary>
    ///<typeparam name="T"></typeparam>
    public abstract class I@(Model.ClassName)<T> :ModelBase<@(Model.ClassName)> where T : @(Model.ClassName), new()
    {
        /// <summary>
        /// 写入主键值
        /// </summary>
        /// <param name="Id">主键</param>
        protected internal override void SetKeyValue(dynamic Id)
        {
            this.@(Model.Columns[0].Code) = Id;
        }

        /// <summary>
        /// 获取主键值
        /// </summary>
        /// <returns></returns>
        protected internal override dynamic GetKeyValue()
        {
            return @(Model.Columns[0].Code);
        }

        /// <summary>
        /// 为本对象赋值
        /// </summary>
        /// <param name="dy"></param>
        public override void SetValue(dynamic dy) 
        {
             @foreach (var info in Model.Columns)
            {
           @("           this.")@(info.Code)@("=")@("dy.")@(info.Code+";");
                         @("\r\n")                               
             }
        } 

        #region 定义属性

@foreach (var info in Model.Columns)
{
     <text>
         /// <summary>
        /// @info.Name
        /// </summary>
        private @(Tool.GetTypeName(info.DataType)) _@(info.Code) @Html.Raw(Tool.GetTypeValue(info.DataType,info.Stereotype));
      
        /// <summary>
        /// @info.Name
        /// </summary>
        public @(Tool.GetTypeName(info.DataType,info.Stereotype,Model.ClassName,info.Code)) @(info.Code)
        {
            get 
            {
              return @(Tool.StringGet(info.Stereotype, Model.ClassName, info.Code))
            }

            set 
            {
                  @(Tool.StringSet(info.Stereotype, Model.ClassName, info.Code))
            }
        }
       </text>
}

      #endregion 定义属性 

          protected internal override void SetValue(@(Model.ClassName) info, DataRow row) 
          { 
               if (row == null) 
               { 
                 info.IsLoad = false; 
               }
               else 
               { 
                  info.IsLoad = true; 
            @foreach (var info in Model.Columns)
            {
                  <text>
                  if(row["@info.Code"]!= DBNull.Value)
                  {
                  info.@(info.Code)=@Html.Raw(Tool.GetConvert(info.DataType, info.Code, info.Stereotype, Model.ClassName));
                 }
                 </text>
            }
               } 

          } 

        protected internal override void GetDbParameters(DbCommand comm, @(Model.ClassName) info, DbHelper cn) 
        { 
         @foreach (var info in Model.Columns)
         {
             if (!info.Code.Equals("Version"))
             {
             <text>
                cn.AddInParameter(comm, "@@@(info.Code)", DbType.@Tool.GetDbTypeName(info.DataType),ParameterTool.GetObj( info._@(info.Code) )); 
            </text>
             }
             else
             {
                <text>
                cn.AddInParameter(comm,"@@Version", DbType.String, Guid.NewGuid().ToString());
              

                cn.AddInParameter(comm,"@@_versionOdl", DbType.String, info._Version); 
                 </text>
             }
         }
        } 

    } 
} 